package com.yeung.swordoffer;

import java.util.ArrayList;

public class 两个链表的第一个公共节点 {
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        ArrayList<ListNode> store = new ArrayList();
        while (pHead1 != null) {
            store.add(pHead1);
            pHead1 = pHead1.next;
        }
        ListNode result = null;
        while (pHead2 != null) {
            if (store.contains(pHead2)) {
                result = pHead2;
                break;
            }
            pHead2 = pHead2.next;
        }
        return result;
    }
}
